package third_exp;

import java.util.Arrays;

public class exp_3 {
    public static void main(String[] args)
    {
        Circle circ = new Circle(4);
        System.out.println(circ.getArea());

        Rectangle rect = new Rectangle(4, 6);
        System.out.println(rect.getArea());

        TotalArea totalArea = new TotalArea();
        for(int i = 0;i < 6;i++){
            totalArea.pushBack(new Circle(i));
            totalArea.pushBack(new Rectangle(i + 1, i + 5));
        }
        System.out.println(totalArea.computeTotalArea());
    }
}


abstract class Geometry
{
    public abstract double getArea();
}

class Circle extends Geometry
{
    private double radius;

    public Circle(double radius)
    {
        this.radius = radius;
    }
    public double getArea()
    {
        return Math.PI * radius * radius;
    }
}

class Rectangle extends Geometry
{
    private double length;
    private double width;

    public Rectangle(double length, double width)
    {
        this.length = length;
        this.width = width;
    }
    public double getArea()
    {
        return length * width;
    }
}

class TotalArea
{
    Geometry[] tuxing;
    private int size;
    private int capacity;

    public TotalArea()
    {
        this.size = 0;
        this.capacity = 3;
        tuxing = new Geometry[capacity];
    }
    public void pushBack(Geometry g)
    {
        if(size >= capacity){
            tuxing = Arrays.copyOf(tuxing, capacity * 2);
            capacity *= 2;
        }
        tuxing[size] = g;
        size += 1;
    }
    public double computeTotalArea()
    {
        double area = 0;
        for(int i = 0; i < size; i++){
            area += tuxing[i].getArea();
        }
        return area;
    }
}